const puppeteer = require("puppeteer")

var list = async ctx=>{
    const browser = await puppeteer.launch({
        headless:false,
        defaultViewport:null
    });
    const page = await browser.newPage()
    await page.goto("https://www.duitang.com/")
    await page.waitForTimeout(3000)
    var res = await page.evaluate(()=>{
        var $ = window.jQuery
        var arr =[]
        var items = $(".content-detail .dynamic-feed-item")
        items.each((index,value)=>{
            var avatar = $(value).find(".user-info img").attr("src")
            var username = $(value).find(".user-desc .username").html()
            var label = $(value).find(".dynamic-album-desc").html()
            var like = $(value).find(".like-action .detail-text").html()
            var start = $(value).find(".favorite-action .detail-text").html()
            var images = []
            var imgs = $(value).find(".dynamic-multi-img-container a")
            imgs.each((index,value)=>{
                var imgUrl = $(value).find("img").attr("src")
                images.push(imgUrl)
            })
            arr.push({
                avatar,
                username,
                images,
                label,
                like,
                start
            })
        })
        return arr
    })
    await browser.close();
    ctx.body = res
}
module.exports = list